<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$videotitle=pdo_getcolumn('jy_xiaoeknow_video',array('id'=>$this->session('video_id'),'uniacid'=>$_SESSION['uniacid'],'merchid'=>$_SESSION['onemerchid']),'title');	
$tabs=array(
	array('op'=>'list','title'=>$videotitle.'-章节列表'),
);
if($_RQ['op']=='list'){
	//搜索
	if($_RQ['id']){
		$this->session('video_id',$_RQ['id']);
	}
	if(!$this->session('video_id')){
		exi('请选择课程！','error');
	}
	$params=array('uniacid'=>$_SESSION['uniacid'],'video_id'=>$this->session('video_id'),'merchid'=>$_SESSION['onemerchid']);
	if($_RQ['title']){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$total='';
	$list=pdo_getslice('jy_xiaoeknow_video_jie',$params,array($pindex,$psize),$total,$fields,'','paixu desc,id desc');
	if($list){
		foreach($list as &$row){
		}
	}
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','tip'=>'<red>章节里面有添加内容列表的，前端才会显示该章节！</red>','delall'=>false,'list'=>array(
			array('name'=>'paixu','title'=>'排序','type'=>'string'),
			array('name'=>'image','title'=>'logo','type'=>'image'),
			array('name'=>'title','title'=>'名称','type'=>'string'),
			array('name'=>'feetype','title'=>'收费类型','type'=>'radio','options'=>'types'),
		),'action'=>array(
			array('type'=>'href','action'=>'jy_xiaoeknow/video_jieitem/','title'=>'内容列表'),
		)
		),
		'search_one'=>array('name'=>'name','add_op'=>'edit')
	);
	$return['types']=$this->video_types;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_xiaoeknow_video_jie',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id,'merchid'=>$_SESSION['onemerchid']));
	}else{
		$item=array();
	}
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'章节详情',
		'tabs'=>$tabs,
		'edit'=>array(
			array('type'=>'string','title'=>'名称','name'=>'title', 'help'=>'' ),
			array('type'=>'image','title'=>'logo','name'=>'image', 'help'=>'' ),
			array('type'=>'text','title'=>'描述','name'=>'desc', 'help'=>'' ),
			array('name'=>'feetype','title'=>'收费类型','type'=>'radio','options'=>'types','help'=>'<red>这里设置收费了，课程内容设置收费不生效</red>；这里不设置收费，后面课程内容可以设置【收费类型】'),
			array('name'=>'price','title'=>'课程价格','type'=>'string','show'=>array('feetype'=>1)),
			array('type'=>'switch','title'=>'是否显示','name'=>'status','help'=>'' ),
			array('type'=>'string','title'=>'排序','name'=>'paixu' , 'help'=>''),
		)
	);
	$return['types']=$this->video_types;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$post=get_postdata();
	$data=array(
		'title'=>trim($post['title']),
		'desc'=>trim($post['desc']),
		'image'=>trim($post['image']),
		'status'=>intval($post['status']),
		'feetype'=>intval($post['feetype']),
		'price'=>trim($post['price']),
		'paixu'=>intval($post['paixu']),
	);
	$id=intval($post['id']);
	if($id){
		pdo_update('jy_xiaoeknow_video_jie',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['merchid']=$_SESSION['onemerchid'];
		$data['video_id']=$this->session('video_id');
		pdo_insert('jy_xiaoeknow_video_jie',$data);
	}
	exi('保存成功！','','list');
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_xiaoeknow_video_jie',array('id'=>$id,'uniacid'=>$_SESSION['uniacid'],'merchid'=>$_SESSION['onemerchid']));
		}
	}
	exi('删除成功！');
}
?>